<!--
Date: 2025-08-13
Copyright (c) 2025 Industrial Software Feature Database
-->
<template>
  <div class="unified-search">
    <Entry v-if="showEntry" @handleEvent="handleEvent" />
    <DataList v-if="showList" type="LinkFromSearch" :params="params" :dataBaseList="dataBaseList" :tableData="dataList" :modelList="modelList" :sceneList="sceneList" :systemList="systemList" :searchItem="searchItem" :modelId="modelId" @handleEvent="handleEvent" />
    <SearchRes v-if="showRes" type="LinkFromSearch" :params="params" :dataBaseList="dataBaseList" :tableData="dataList" :modelList="modelList" :sceneList="sceneList" :systemList="systemList" :searchItem="searchItem" :modelId="modelId" @handleEvent="handleEvent" />
  </div>
</template>
<script setup name="UnifiedSearch">
import Entry from './pages/Entry.vue';
import DataList from './pages/DataList.vue';
import SearchRes from './pages/SearchRes.vue';
const showEntry = ref(true);
const showList = ref(false);
const showRes = ref(false);
const searchItem = ref({});
const modelId = ref('');
const dataList = ref([]);
const modelList = ref([]);
const sceneList = ref([]);
const systemList = ref([]); 
const dataBaseList = ref([]);
const params = ref({});
const handleEvent = (data) => {
  if (data.component === 'List') {
    showList.value = true;
    showEntry.value = false;
    showRes.value = false;
    // searchItem.value = data?.searchItem;
    dataList.value = data?.dataList || [];
    modelList.value = data?.modelList || [];
    systemList.value = data?.systemList || [];
    sceneList.value = data?.sceneList || [];
    dataBaseList.value = data?.dataBaseList || [];
    params.value = data?.params || {};
    modelId.value = data?.modelId;
  }
  if (data.component === 'Entry') {
    showList.value = false;
    showEntry.value = true;
    showRes.value = false;
    // searchItem.value = data?.searchItem;
    dataList = data?.dataList || [];
    modelList = data?.modelList || [];
    systemList = data?.systemList || [];
    sceneList = data?.sceneList || [];
    dataBaseList.value = data?.dataBaseList || [];
    params.value = data?.params || {};
    modelId.value = data?.modelId;
  }
  if (data.component === 'Result') {
    showList.value = false;
    showEntry.value = false;
    showRes.value = true;
    searchItem.value = data?.searchItem;
    modelId.value = data?.modelId;
  }
};
onMounted(() => {
  // tableName.value = route.query?.tableName || '';
})
</script>
<style lang="scss" scoped>
.unified-search {
  height: calc(100vh - 84px);
  width: 100%;
  overflow-y: auto;
  // max-width: 1200px;
  // margin: 20px auto;
  // // padding: 2rem;
  // background: #f8f9fa;
  // border-radius: 12px;
  // box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}
</style>